package com.ruoyi.property.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.property.domain.TProperty;
import com.ruoyi.property.service.ITPropertyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 二手房源列表Controller
 * 
 * @author ruoyi
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/property")
public class TPropertyController extends BaseController
{
    @Autowired
    private ITPropertyService tPropertyService;

    /**
     * 查询二手房源列表列表
     */
    @RequiresPermissions("property:property:list")
    @GetMapping("/list")
    public TableDataInfo list(TProperty tProperty)
    {
        startPage();
        List<TProperty> list = tPropertyService.selectTPropertyList(tProperty);
        return getDataTable(list);
    }

    /**
     * 导出二手房源列表列表
     */
    @RequiresPermissions("property:property:export")
    @Log(title = "二手房源列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProperty tProperty)
    {
        List<TProperty> list = tPropertyService.selectTPropertyList(tProperty);
        ExcelUtil<TProperty> util = new ExcelUtil<TProperty>(TProperty.class);
        util.exportExcel(response, list, "二手房源列表数据");
    }

    /**
     * 获取二手房源列表详细信息
     */
    @RequiresPermissions("property:property:query")
    @GetMapping(value = "/{propertyId}")
    public AjaxResult getInfo(@PathVariable("propertyId") Long propertyId)
    {
        return success(tPropertyService.selectTPropertyByPropertyId(propertyId));
    }

    /**
     * 新增二手房源列表
     */
    @RequiresPermissions("property:property:add")
    @Log(title = "二手房源列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProperty tProperty)
    {
        return toAjax(tPropertyService.insertTProperty(tProperty));
    }

    /**
     * 修改二手房源列表
     */
    @RequiresPermissions("property:property:edit")
    @Log(title = "二手房源列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProperty tProperty)
    {
        return toAjax(tPropertyService.updateTProperty(tProperty));
    }

    /**
     * 删除二手房源列表
     */
    @RequiresPermissions("property:property:remove")
    @Log(title = "二手房源列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{propertyIds}")
    public AjaxResult remove(@PathVariable Long[] propertyIds)
    {
        return toAjax(tPropertyService.deleteTPropertyByPropertyIds(propertyIds));
    }
}
